package edu.fit5046.mymonashmate.activity;

import java.util.ArrayList;
import java.util.List;

import com.mapquest.android.maps.AnnotationView;
import com.mapquest.android.maps.DefaultItemizedOverlay;
import com.mapquest.android.maps.GeoPoint;
import com.mapquest.android.maps.ItemizedOverlay;
import com.mapquest.android.maps.MapView;
import com.mapquest.android.maps.OverlayItem;

import edu.fit5046.mymonashmate.R;
import edu.fit5046.mymonashmate.utils.SimpleInfo;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MapActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_map);

		/*if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, new PlaceholderFragment()).commit();
		}*/
		
		// set the zoom level, center point and enable the default zoom controls
		MapView map = (MapView) findViewById(R.id.map); 
		map.getController().setZoom(9);
		map.getController().setCenter(new GeoPoint(-37.876470, 145.044078)); 
		map.setBuiltInZoomControls(true);
		/*FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE*/
		SimpleInfo ps1 = new SimpleInfo(24824925, -37.876470, 145.044078, "Mingli Yang", "Master of IT Professional", 8);
		SimpleInfo ps2 = new SimpleInfo(23423434, -37.924724, 145.120795, "Chen Chen", "Master of Applied IT", 6);
		SimpleInfo ps3 = new SimpleInfo(23442434, -37.876470, 145.120795, "Che", "Master of Applied IT", 2);
		SimpleInfo ps4 = new SimpleInfo(23423334, -37.924724, 145.044078, "hen Chen", "Master of Applied IT", 4);
		SimpleInfo ps5 = new SimpleInfo(29423434, -37.876470, 145.044093, "Chen henhen", "Master of Applied IT", 7);
		/*FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE FAKE*/
		
		// use a custom POI marker by referencing the bitmap file directly,
		// using the filename as the resource ID
		Drawable icon = getResources().getDrawable(R.drawable.location_marker);
		final DefaultItemizedOverlay poiOverlay = new DefaultItemizedOverlay(icon);
		
		
		
		// set GeoPoints and title/snippet to be used in the annotation view
	      OverlayItem local = new OverlayItem(new GeoPoint (-37.876470, 145.044078),
	"Mingli Yang", "Master of Infomation Technology Professional");
	      poiOverlay.addItem(local);
	      
	      /*Mingli Gai *001*/
	      List<SimpleInfo> list = new ArrayList<SimpleInfo>();
	      list.add(ps1);
	      list.add(ps2);
	      list.add(ps3);
	      list.add(ps4);
	      list.add(ps5);
			
	      for(int i=0;i<list.size();i++){
	    	  SimpleInfo p =(SimpleInfo)list.get(i);
	    	  OverlayItem poi1 = new OverlayItem(new GeoPoint (p.latitude, p.longitude),
	    			  p.Name, p.course);
	      poiOverlay.addItem(poi1);
	      }
	      /*Mingli Gai #001*/
	      
	      
	      
	      final AnnotationView annotation = new AnnotationView(map);
	      // add a tap listener for the POI overlay
	      poiOverlay.setTapListener(new ItemizedOverlay.OverlayTapListener() {
	      @Override
	        public void onTap(GeoPoint pt, MapView mapView) {
	           // when tapped, show the annotation for the overlayItem
	           int lastTouchedIndex = poiOverlay.getLastFocusedIndex();
	           if(lastTouchedIndex>-1){
	               OverlayItem tapped = poiOverlay.getItem(lastTouchedIndex);
	               annotation.showAnnotationView(tapped);
	           }
	      } });
	      
	      
	      map.getOverlays().add(poiOverlay);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
//		int id = item.getItemId();
//		if (id == R.id.action_settings) {
//			return true;
//		}
		return super.onOptionsItemSelected(item);
	}


}
